package com.yzg.redis.web.controller;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RequestInterceptor extends HandlerInterceptorAdapter {


    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handle) throws Exception {
    	String requestURI=request.getRequestURI();
        requestURI = requestURI==null ? "":requestURI;
        try {
        	 //出现了乱码问题
            request.setCharacterEncoding("UTF-8");
            response.setCharacterEncoding("UTF-8");
            response.setHeader("Access-Control-Allow-Origin", "*");//配合网页测试，上线前必须注释
//            if(requestURI != null) {
//            	if(requestURI.indexOf("/login")>-1)
//            		return true;
//            	else if(!userTracker.isLogined(request))
//            		return false;
//            }
            
            return true;
		} catch (Exception e) {
			e.printStackTrace();
//            log.error("拦截器异常："+e,e);
            return false;
		}
    }
}
